<?php

/**
 * cancelacion actions.
 *
 * @package    cronos-doctrine
 * @subpackage cancelacion
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class cancelacionActions extends sfActions
{
 

  public function executeNew(sfWebRequest $request)
  {
    
    //Capturo las variables   
    $this->idUser = $request->getParameter('idUser');
    $this->idAgendado = $request->getParameter('idAgendado');
    
    $this->form = new CancelacionForm();
    $this->form->setWidget('usuario_id', new sfWidgetFormInputHidden(array(),array('value' => $this->idUser )));
    $this->form->setWidget('agendado_id', new sfWidgetFormInputHidden(array(),array('value' => $this->idAgendado )));
    
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new CancelacionForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }


  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      
      $cancelacion  = $form->save();
    
      if($cancelacion){
        
          $agendado     = Doctrine_Query::create()
                        ->set('agendado_status_id', '4')
                        ->update('Agendado ag')
                        ->where('ag.id=?',$cancelacion->getAgendadoId())
                        ->execute();
      }
      
      
      $this->redirect('agendado/formDetalle?idAgendado='.$cancelacion->getAgendadoId().'&notice=1');
      
    }
  }
  
  
  
}
